
import { systemDictDetail } from '@/api/system';
import cityData from '@/utils/cityList.js';
import { createPayload, filterData } from '@/utils'
import moment from 'moment'

export default {
  data () {
    return {
      pageParams: {},
      allList: [], // 接口返回数据（未处理）
      list: [], // table 显示符合条件数据
      pageSizes: [50, 100, 150, 200],
      paging: { // 分页参数 page：当前页码，limit：每页条数，total： 总条数
        page: 1,
        limit: 20,
        total: 0
      },
      query: {}
    }
  },
  computed: {
    curStore () {
      const curStore = this.$store.getters.curStore;
      return curStore;
    },
    storeHouseList () {
      const list = this.$store.state.store.storeHouseList;
      const curStoreHouseList = list.filter(d => d.store_id === this.curStore.id)
      return curStoreHouseList;
    },
    system () {
      const system = this.$store.getters.system;
      console.log('curde--system==', system);
      // this.handleComputedUpdata(system);
      return system;
    },
    dictData () {
      const dictData = this.$store.state.system.dictData;
      console.log('curd--dictData==', dictData);
      return dictData?.data;
    },
    dictDetails () {
      const system = this.$store.getters.system;
      const { dictDetails, dictObj } = system;
      console.log('curde--system==', system);
      console.log('curde--dictDetails==', dictDetails, dictObj);
      return dictDetails;
    },
    dictObj () {
      const system = this.$store.getters.system;
      const { dictObj } = system;
      return dictObj;
    },
    // 客户类型；
    company_type () {
      console.log('curde--this.dictDetails==', this.dictDetails);
      if (this.dictDetails && this.dictDetails?.company_type && this.dictDetails?.company_type?.data) {
        return this.dictDetails?.company_type?.data || []
      }
      return [];
    },
    // 省市数据；
    provice_citys () {
      return cityData.provice_citys
    }
  },
  created () {
    this.pageParams = this.$route.params;
  },
  methods: {
    handleDict (dictName) {
      // console.log('curde--handleDict--this.dictData==', this.dictData);
      if (dictName && this.dictData && this.dictData.length) {
        const dict = this.dictData.find(d => d.name === dictName)
        // console.log('curde--handleDict==', dictName, dict);
        return dict || { data: [] };
      }
      else {
        console.log('curde--handleDict--this.dictData==', this.dictData);
      }
      return { data: [] };
    },
    handleDate (value, format = 'YYYY-MM-DD') {
      return value ? moment(value).format(format) : '';
    },
    // 处理对象，过滤对象中的空元素；
    createPayload,
    // 按条件过滤列表数据；
    filterData,
    async getDictDetail () {
      if (!this.selDict?.id) return;
      const payload = { dict_id: this.selDict?.id }
      const { data } = await systemDictDetail(payload);
      this.dictDetailList = data?.list || [];
      this.$store.dispatch('system/updateDictDetail', { data: this.dictDetailList, name: this.selDict.name })
      console.log('this.dictDetailList==', this.dictDetailList);
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`);
    }
  }
}
